import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
import 'package:logger/logger.dart';
import 'package:flutter_architecture/utils/log_util.dart';
/// 欢迎页面，视频播放 widget
/// @author: dingwen
/// @date: 2021/1/3

class VideoWidget extends StatefulWidget {
  @override
  _VideoWidgetState createState() => _VideoWidgetState();
}

class _VideoWidgetState extends State<VideoWidget> {
  ///视频播放器控制器
  VideoPlayerController _videoPlayerController;

  @override
  void initState() {
    super.initState();
    ///控制器初始化，视频加载
    _videoPlayerController = VideoPlayerController.asset('video/welcome.mp4')
    ..initialize().then((value){
      _videoPlayerController.play();
      log(level: Level.info,fileName: 'video.widget.dart',functionName: 'initialize',message: '视频加载成功');
      setState(() {});
    });
  }
  @override
  Widget build(BuildContext context) {
    double width = MediaQuery.of(context).size.width;
    double height = MediaQuery.of(context).size.height;
    return _videoPlayerController.value.initialized ?  SizedBox(
      width: width,
      height: height,
      child: AspectRatio(
        aspectRatio: _videoPlayerController.value.aspectRatio,
        child: VideoPlayer(_videoPlayerController)),
    ):Container();
  }

  @override
  void dispose() {
    super.dispose();
    _videoPlayerController.dispose();
  }
}
